package com.jiangnan.util

import android.content.Context
import android.view.LayoutInflater
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.jiangnan.databinding.DialogQrPaymentBinding

fun showQrPaymentDialog(
  context: Context,
  qrDrawableRes: Int,
  message: String,
  onConfirm: () -> Unit
) {
  // 1. 用 ViewBinding 加载自定义布局
  val binding = DialogQrPaymentBinding.inflate(LayoutInflater.from(context))

  // 2. 设置二维码和提示文字
  binding.ivQrCode.setImageResource(qrDrawableRes)
  binding.tvMessage.text = message

  // 3. 创建对话框
  val dialog = MaterialAlertDialogBuilder(context)
    .setView(binding.root)
    .setCancelable(false)
    .show()

  // 4. 绑定按钮事件
  binding.btnCancel.setOnClickListener {
    dialog.dismiss()
  }
  binding.btnConfirm.setOnClickListener {
    dialog.dismiss()
    onConfirm()
  }
}
